package com.x.Servlet_08_Cookie;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

/**
 * ClassName: ServletA
 * Package: IntelliJ IDEA
 * Description:
 * Written by HanXu
 * Create 2024.08.28 13:58
 */

@WebServlet("/CookieTest1")
public class ServletA extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //创建cookie
        Cookie cookie1 = new Cookie("key1", "value1");
        Cookie cookie2 = new Cookie("key2", "value2");

        //设置cookie活跃时长
        cookie1.setMaxAge(60*5);//使cookie1保持5分钟

        //将cookie放入ServletResponse
        resp.addCookie(cookie1);
        resp.addCookie(cookie2);
    }
}
